package com.chinairi.mall.controller;


import com.chinairi.common.controller.BaseController;
import com.chinairi.common.utils.ResponseUtil;
import com.chinairi.mall.controller.viewobject.*;
import com.chinairi.mall.model.ManagerInfo;
import com.chinairi.mall.model.OrderInfo;
import com.chinairi.mall.model.Project;
import com.chinairi.mall.service.IProjectService;
import com.chinairi.mall.service.modelobject.*;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 项目表 前端控制器
 * </p>
 *
 * @author gsl
 * @since 2020-08-23
 */
@RestController
@Api
@RequestMapping("/project")
public class ProjectController extends BaseController {

    @Autowired
    private IProjectService projectService;

    /**
     * 新增项目
     *
     * @param projectVO
     * @throws IOException
     */
    @PostMapping("/add")
    public void addProject(@RequestBody ProjectVO projectVO) throws IOException {
        projectService.addProject(projectVO);
        ResponseUtil.showMessage("success", "新建项目成功", "");
    }

    /**
     * 新增项目
     *
     * @param projectVO
     * @throws IOException
     */
    @PostMapping("/addService")
    public void addService(@RequestBody ProjectVO projectVO) throws IOException {
        projectService.addService(projectVO);
        ResponseUtil.showMessage("success", "提交项目服务中心成功", "");
    }

    /**
     * 获取本单位下项目列表
     * 包含根据项目名称和类型查询
     *
     * @throws IOException
     */
    @GetMapping("/getList")
    public void getList(ProjectVO projectVO) throws IOException {
        List<ProjectVO> projectVOList = projectService.getList(projectVO);
        ResponseUtil.showMessage("success", "获取项目列表成功", projectVOList);
    }

    /**
     * 更新项目
     *
     * @param projectVO
     * @throws IOException
     */
    @PutMapping("/update")
    public void updateProject(@RequestBody ProjectVO projectVO) throws IOException {
        projectService.updateProject(projectVO);
        ResponseUtil.showMessage("success", "更新项目成功", "");
    }

    /**
     * 根据项目id获取项目详情
     *
     * @param pId
     * @throws IOException
     */
    @GetMapping("/getById")
    public void getById(String pId) throws IOException {
        Project project = projectService.getById(pId);
        ResponseUtil.showMessage("success", "获取详细信息成功", project);
    }

    /**
     * 删除项目
     *
     * @param pId
     * @throws IOException
     */
    @DeleteMapping("/delete")
    public void deleteProject(String pId) throws IOException {
        projectService.deleteProject(pId);
        ResponseUtil.showMessage("success", "删除项目成功", "");
    }

    /**
     * 查询项目
     *
     * @param projectVO
     * @throws IOException
     */
    @GetMapping("/select")
    public void selectProject(ProjectVO projectVO) throws IOException {
        List<Project> projectVOList = projectService.selectProject(projectVO);
        ResponseUtil.showMessage("success", "查询项目成功", projectVOList);
    }

    /**
     * 获取库点
     *
     * @throws IOException
     */
    @GetMapping("/getStorage")
    public void getStorage() throws IOException {
        List<StorageAddressVO> storageAddressVOList = projectService.getStorage();
        ResponseUtil.showMessage("success", "获取成功", storageAddressVOList);
    }

    /**
     * 获取所有企业的项目信息
     *
     * @param projectInfoOfAllCompMo
     * @throws IOException
     */
    @GetMapping("/getProjectInfoOfAllComp")
    public void getProjectInfoOfAllComp(ProjectInfoOfAllCompMO projectInfoOfAllCompMo) throws IOException {
        List<ProjectInfoOfAllCompMO> list = projectService.getProjectInfoOfAllComp(projectInfoOfAllCompMo);
        ResponseUtil.showMessage("success", "获取成功", list);
    }

    /**
     * 根据企业名称查找项目及订单数/花费数
     *
     * @param allInfoMo
     * @throws IOException
     */
    @GetMapping("/getAllInfoOfProject")
    public void getAllInfoOfProject(AllInfoMO allInfoMo) throws IOException {
        List<AllInfoMO> list = projectService.getAllInfoOfOrder(allInfoMo);
        ResponseUtil.showMessage("success", "获取成功", list);
    }

    /**
     * 平台管理员查看平台所有企业信息
     * @throws IOException e
     */
    @GetMapping("getAllCompanyInfo")
    public void getAllCompanyInfo() throws IOException {
        AllCompanyInfoVO infoVO = projectService.getAllCompanyInfo();
        ResponseUtil.showMessage("success","获取成功",infoVO);
    }


    /**
     * 根据企业id查找项目
     * @param uciDbId
     */
    @GetMapping("AllProjectInfoOfCompany")
    public void getAllProjectInfoOfCompany(String uciDbId) throws IOException {
        AllProjectInfoOfCompany info = projectService.getAllProjectInfoOfCompany(uciDbId);
        ResponseUtil.showMessage("success","获取成功",info);
    }

    /**
     * 根据项目id查询项目下所有订单信息
     * @param pid 项目id
     * @param state 订单状态 0-未完成订单 1-已完成订单
     * @throws IOException e
     */
    @GetMapping("AllOrderInfo")
    public void getAllOrderInfoOfProject(String pid,String state) throws IOException {
        List<OrderInfo> orderInfoList = projectService.getAllOrderInfoOfProject(pid,state);
        ResponseUtil.showMessage("success","获取成功",orderInfoList);
    }

    /**
     * 根据项目id查询项目下所有订单信息
     * @param pid 项目id
     * @param state 订单状态 0-未完成订单 1-已完成订单
     * @throws IOException e
     */
    @GetMapping("OrderInfo")
    public void getOrderInfoOfProject(String pid,String state) throws IOException {
        OrderInfoOfPro info = projectService.getOrderInfoOfProject(pid,state);
        ResponseUtil.showMessage("success","获取成功",info);
    }

    /**
     * 根据项目id查询项目下所有需求计划详情
     *
     * @param pid   项目id
     * @param state 需求计划状态 0-未完成需求计划 1-已完成需求计划
     * @throws IOException e
     */
    @GetMapping("AllPlanReqDetailInfo")
    public void getAllPlanReqDetailInfoOfProject(String pid, String state) throws IOException {
        List<ProjectPlanReqDetailMO> detailMOList = projectService.getAllPlanReqDetailInfoOfProject(pid, state);
        ResponseUtil.showMessage("success", "获取成功", detailMOList);
    }

    /**
     * 根据项目id查询项目下所有需求计划信息
     *
     * @param pid   项目id
     * @throws IOException e
     */
    @GetMapping("AllPlanReqInfo")
    public void getAllPlanReqInfoOfProject(String pid) throws IOException {
        ProjectPlanReqInfoVO infoVO = projectService.getAllPlanReqInfoOfProject(pid);
        ResponseUtil.showMessage("success", "获取成功", infoVO);
    }

    /**
     * 根据项目id和工序查看物料清单
     * @param pid 项目id
     * @param planProcess 工序 0-完井 1-一开 2-二开 3-三开 4-四开 5-五开
     * @throws IOException e
     */
    @GetMapping("AllInfoOfBOM")
    public void getAllInfoOfBOM(String pid,String planProcess) throws IOException {
        List<ProjectPlanReqDetailMO> detailMOList = projectService.getAllInfoOfBOM(pid,planProcess);
        ResponseUtil.showMessage("success","获取成功",detailMOList);
    }

    /**
     * 查询项目井别信息
     * @param pId 项目id
     * @throws IOException e
     */
    @GetMapping("getWellInfoOfProject")
    public void getWellInfoOfProject(String pId) throws IOException {
        Project project = projectService.getWellInfo(pId);
        ResponseUtil.showMessage("success","获取成功",project);
    }

    /**
     * 获取所有工序对应的需求物资数和到货物资数
     * @param pid 项目id
     * @throws IOException e
     */
    @GetMapping("getReqMatNumber")
    public void getReqMatNumber(String pid) throws IOException {
        List<ReqMatNumber> list = projectService.getReqMatNumber(pid);
        ResponseUtil.showMessage("success","获取成功",list);
    }

    /**
     * 领导驾驶舱数据展示
     * @throws IOException e
     */
    @GetMapping("getManagerInfo")
    public void getManagerInfo() throws IOException {
        ManagerInfo info = projectService.getManagerInfo();
        ResponseUtil.showMessage("success","获取成功",info);
    }
    /**
     * 用于订单详情展示,前端用此接口用于采购商和供应商的回传，采购商回传项目id，供应商回传店铺id，
     * 需回传flag来判断。正常来说是不能通过是否回传项目名称/id来判断的，必须用flag来做区别，归根结底是前端用户缓存没有店铺信息这一项。
     * 如果必要的话用户在进入店铺页面时需要调取店铺的基本信息就必须获取一次店铺id
     * 但是问题是用户不仅仅有一个店铺，也和用户的操作顺序有很大关系。则用户在回传flag的同时还要回店铺类型，直接精确搜索店铺的id
     * 最直接的是店铺id，最根本的是供应商id。。
     * int型字段flag = 1 表示店铺订单查看，0表示项目归集查看，string型字段type和店铺模块规定的type一致
     *
     * @param allInfoOfOrderMo
     * @throws IOException
     */
    @GetMapping("/getAllInfoOfOrder")
    public void getAllInfoOfOrder(AllInfoOfOrderMO allInfoOfOrderMo) throws IOException {
        List<AllInfoOfOrderMO> list = projectService.getAllInfoOfOrder(allInfoOfOrderMo);
        ResponseUtil.showMessage("success", "获取成功", list);
    }

    /**
     * 获取某个订单下的实物商品
     *
     * @param goodsInfoOfOrderMo
     * @throws IOException
     */
    @GetMapping("/getGoodsInfoOfOrder")
    public void getGoodsInfoOfOrder(GoodsInfoOfOrderMO goodsInfoOfOrderMo) throws IOException {
        List<GoodsInfoOfOrderMO> list = projectService.getGoodsInfoOfOrder(goodsInfoOfOrderMo);
        ResponseUtil.showMessage("success", "获取成功", list);
    }

    /**
     * 获取某个物料的生产信息
     *
     * @param productionInfoOfOrderMo
     * @throws IOException
     */
    @GetMapping("/getProductionInfoOfOrder")
    public void getProductionInfoOfOrder(ProductionInfoOfOrderMO productionInfoOfOrderMo) throws IOException {
        List<ProductionInfoOfOrderMO> list = projectService.getProductionInfoOfOrder(productionInfoOfOrderMo);
        ResponseUtil.showMessage("success", "获取成功", list);
    }

    /**
     * 根据订单的id，获取订单下的实物商品信息
     *
     * @param orderId 订单id
     * @throws IOException
     */
    @GetMapping("/getGoodsByOrderId")
    public void getGoodsByOrderId(String orderId) throws IOException {
        OrderInforGoodsVO orderInforGoodsVO = projectService.getGoodsByOrderId(orderId);
        List<OrderGoodsVO> list = projectService.getGoodsListByOrderId(orderId);
        orderInforGoodsVO.setOrderGoodsVOList(list);
        ResponseUtil.showMessage("success", "获取成功", orderInforGoodsVO);
    }

}
